package lib.bone.nepudata.service.impl;

import lib.bone.access.constant.ResearchTypeConst;
import lib.bone.common.constant.ResponseCodeConst;
import lib.bone.common.core.domain.ResponseDTO;
import lib.bone.nepudata.service.NepuEntityService;
import lib.bone.nepudata.service.ResearchServiceCtl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author kindear
 */

/**
 * cg
 */
@Slf4j
@Service
public class NepuEntityServiceImpl implements NepuEntityService {

    @Autowired
    ResearchServiceCtl researchServiceCtl;


    @Override
    public ResponseDTO getNepuEntity(String type, String id) {
        if (type.equals(ResearchTypeConst.SUBJECT)){
           Optional<Object> entityOp = researchServiceCtl.getById(id,ResearchTypeConst.SUBJECT);
           if (entityOp.isPresent()){
               return ResponseDTO.succData(entityOp.get());
           }
           return ResponseDTO.wrap(ResponseCodeConst.NOT_FOUND);
        }else if (type.equals(ResearchTypeConst.PROPERTY)){
            Optional<Object> entityOp = researchServiceCtl.getById(id,ResearchTypeConst.PROPERTY);
            if (entityOp.isPresent()){
                return ResponseDTO.succData(entityOp.get());
            }
            return ResponseDTO.wrap(ResponseCodeConst.NOT_FOUND);
        }else if (type.equals(ResearchTypeConst.TOPIC)){
            Optional<Object> entityOp = researchServiceCtl.getById(id,ResearchTypeConst.TOPIC);
            if (entityOp.isPresent()){
                return ResponseDTO.succData(entityOp.get());
            }
            return ResponseDTO.wrap(ResponseCodeConst.NOT_FOUND);
        }else if (type.equals(ResearchTypeConst.THINKTANK)){
            Optional<Object> entityOp = researchServiceCtl.getById(id,ResearchTypeConst.THINKTANK);
            if (entityOp.isPresent()){
                return ResponseDTO.succData(entityOp.get());
            }
            return ResponseDTO.wrap(ResponseCodeConst.NOT_FOUND);
        }else if (type.equals(ResearchTypeConst.AWARD)){
            Optional<Object> entityOp = researchServiceCtl.getById(id,ResearchTypeConst.AWARD);
            if (entityOp.isPresent()){
                return ResponseDTO.succData(entityOp.get());
            }
            return ResponseDTO.wrap(ResponseCodeConst.NOT_FOUND);
        }else if (type.equals(ResearchTypeConst.BOOK)){
            Optional<Object> entityOp = researchServiceCtl.getById(id,ResearchTypeConst.BOOK);
            if (entityOp.isPresent()){
                return ResponseDTO.succData(entityOp.get());
            }
            return ResponseDTO.wrap(ResponseCodeConst.NOT_FOUND);
        }else if (type.equals(ResearchTypeConst.PAPER)){
            Optional<Object> entityOp = researchServiceCtl.getById(id,ResearchTypeConst.PAPER);
            if (entityOp.isPresent()){
                return ResponseDTO.succData(entityOp.get());
            }
            return ResponseDTO.wrap(ResponseCodeConst.NOT_FOUND);
        }
        return null;
    }
}
